<include file="../Public/_top" />
<div class="content">
  <div class="wrap">
    <include file="./_left" />
    <div class="con_main">
      <div class="con_tit">
        <ul class="con_link">
          <li><a href="{:U('public/Index/index')}">班级列表</a></li>
          <li><a href="{:U('public/Index/addClass')}">新建班级</a></li>
          <li class="on"><a href="javascript:;">恢复班级数据</a></li>
        </ul>
      </div>
      <div style="width:100%;height:70px;padding:15px;">
        <div class="sel_box">
          年级类型：
          <select id="class_type" class="sel" onchange="selectClass();">
            <option value="">--------请选择--------</option>
            <option value="1">大班</option>
            <option value="2">中班</option>
            <option value="3">小班</option>
            <option value="4">混龄班</option>
          </select>
        </div>
      </div>
      <div class="con_tit">
        <table class="table table_title t61">
          <tr>
            <td>
              <input id="select-all" type="checkbox" value="1" />
            </td>
            <td>班级id</td>
            <td>建档年份</td>
            <td>班级名称</td>
            <td>班级状态</td>
            <td>登录名</td>
            <td>登录密码</td>
            <td>操作</td>
          </tr>
        </table>
      </div>
      <div class="con_box" id="grade_list"></div>
    </div>
  </div>
</div>

<script>
  $('#select-all').click(function () {
    var checked = $(this).attr('checked')
    if (checked) {
      $(this).attr('checked', 'checked')
      $('.select-item').attr('checked', 'checked')
    } else {
      $(this).attr('checked', false)
      $('.select-item').attr('checked', false)
    }

    var ids = []
    $('.select-item').each(function () {
      if ($(this).attr('checked') == 'checked') {
        ids.push($(this).val())
      }
    })

    if (ids.length > 0) {
      $('#class-upgrade').removeClass('disabled').addClass('upgrade')
    } else {
      $('#class-upgrade').removeClass('upgrade').addClass('disabled')
    }
  })

  $(document).on('click', '.select-item', function () {
    var ids = []
    $('.select-item').each(function () {
      if ($(this).attr('checked') == 'checked') {
        ids.push($(this).val())
      }
    })

    if (ids.length > 0) {
      $('#class-upgrade').removeClass('disabled').addClass('upgrade')
    } else {
      $('#class-upgrade').removeClass('upgrade').addClass('disabled')
    }
  })

  function selectClass() {
    var class_type = $("#class_type").val();
    if (class_type) {
      $.ajax({
        type: "GET",
        url: "{:U('public/Index/getDelClassList')}",
        data: "p=1&class_type=" + class_type,
        dataType: "json",
        success: function (data) {
          $('#select-all').attr('checked', false)
          appendHtml(data);
        }
      });
    }
  }
  //追加html
  function appendHtml(data) {
    $("#grade_list").html("");
    $("#grade_list").append(data.data);
  }

  function RestoreClass(id, admin_id, type) {
    if (confirm('你确定要恢复这个班级')) {
      $.ajax({
        type: "POST",
        url: "{:U('public/Index/RestoreClass')}",
        data: "id=" + id + "&admin_id=" + admin_id + "&type=" + type,
        dataType: "text",
        success: function (data) {
          if (isNaN(data)) {
            alert(data);
          } else {
            window.location.href = window.location.href;
          }
        }
      });
    }
  }

</script>
<include file="../Public/_foot" />